﻿#region Copyright 2008 - Evolution Systems.
//
// Author: José Rogério Ferreira dos Santos(joserogerio.santos@gmail.com)
// Date: 03/01/2009
// Time: 19:07
// All rights are reserved. Reproduction or transmission in whole or in part, in
// any form or by any means, eletronic, mechanical or otherwise, is prohibited
// without the prior written permission of the author.
//
// Filename: ${FILE_NAME}.cs
#endregion
using System;
using System.Collections.Generic;

namespace csharp.rad.general
{
	/// <summary>
	/// Description of Visit.
	/// </summary>
	public class Visit : csharp.common.DefaultClass, csharp.common.IClass
	{
		#region private declaration 
			private string _employee_id; 
			private string _register_date; 
			private string _date; 
			private string _situation; 
			private string _contact_type; 
			private string _customer_id; 
			private string _obs;		
		#endregion
		
		public Visit()
		{
			clear();
			gsql.table = "common.visit";
			_sequence  = "common.visit_visit_id_seq";
		}
		
		#region properties
			public string employeeId 
			{
				get { return _employee_id; }
				set { _employee_id = value; }
			}
			
			public string registerDate 
			{
				get { return _register_date; }
				set { _register_date = value; }
			}
			
			public string date 
			{
				get { return _date; }
				set { _date = value; }
			}
			
			public string situation 
			{
				get { return _situation; }
				set { _situation = value; }
			}
			
			public string contactType 
			{
				get { return _contact_type; }
				set { _contact_type = value; }
			}
			
			public string customerId 
			{
				get { return _customer_id; }
				set { _customer_id = value; }
			}
			
			public string obs 
			{
				get { return _obs; }
				set { _obs = value; }
			}
			
		#endregion
		
		public void clear()
		{
			_id				= String.Empty;
			_employee_id	= String.Empty; 
			_register_date	= String.Empty; 
			_date				= String.Empty; 
			_situation		= String.Empty; 
			_contact_type	= String.Empty; 
			_customer_id   = String.Empty; 
			_obs				= String.Empty;			
		}
		
		public override void get(System.Data.DataRow dr)
		{
			_id=            dr["visit_id"].ToString();  
			_employee_id=   dr["visit_employee_id"].ToString(); 
			_register_date= Convert.ToDateTime(dr["visit_register_date"]).ToString("dd/MM/yyyy");
			_date=          Convert.ToDateTime(dr["visit_date"]).ToString("dd/MM/yyyy"); 
			_situation=     dr["visit_situation"].ToString(); 
			_contact_type=  dr["visit_contact_type"].ToString(); 
			_customer_id=   dr["visit_customer_id"].ToString(); 
			_obs=           dr["visit_obs"].ToString();			
		}
		
		public override void setGsql()
		{
			//gsql.setValue(_id,            "visit_id");  
			gsql.setValue(_employee_id,   "visit_employee_id"); 
			//gsql.setValue(Convert.ToDateTime(_register_date).ToString("yyyy/MM/dd"), "visit_register_date");
			gsql.setValue(Convert.ToDateTime(_date).ToString("yyyy/MM/dd"),          "visit_date"); 
			gsql.setValue(_situation,     "visit_situation"); 
			gsql.setValue(_contact_type,  "visit_contact_type"); 
			gsql.setValue(_customer_id,   "visit_customer_id"); 
			gsql.setValue(_obs,           "visit_obs"); 
		}
		
	}
	
	public class Visits : csharp.common.DefaultList, csharp.common.IList
	{
		public Visits()
		{
			gsql.table = "common.visit";
		}

		/*public List<Visit> items
		{
			get { return items; }
		}*/
		
		public Visit get(Int32 index)
		{
			return (Visit)items[index];
		}
		
		public Visit get()
		{
			return (Visit)items[index];
		}		
		
		public bool fillList()
		{
			gsql.prepare();
			gsql.setValue("","*");
			gsql.additionalWhere = "ORDER BY visit_date";
			
			return mountList();
		}
		
		public bool fillList(string customerId)
		{
			gsql.prepare();
			gsql.setValue("","*");
			gsql.conditionalWhere = "visit_customer_id = "+customerId;
			gsql.additionalWhere = "ORDER BY visit_date";
			
			return mountList();
		}
		
		private bool mountList()
		{
			Int32 tam;
			
			if (!gsql.execute())
				return false;
			
			tam = gsql.getRowCount();
			items.Clear();
			for (int i=0; i < tam; i++)
			{
				Visit c = new Visit();
				c.get(gsql.getRow(i));
				items.Add(c);
			}
			return true;
		}
	}
	
}
